package P1.Lynn;
import java.util.Scanner;
import java.math.*;

/*************************************************************************
* Project 1: Classifies triangles according to the input three numbers 
* represents the lengths of sides of a triangle 
* 
* Author: Lynn Lin
**************************************************************************/
public class decideTriangleType {
	
	/* Private class members */
	private float side1 = 0.0F;
	private float side2 = 0.0F;
	private float side3 = 0.0F;
	
	/*------------------------------------------------------
	 * isRightTriangle() decides if triangle is a 
	 * right triangle given 3 sides.
	 * -----------------------------------------------------
	 */	
	private boolean isRightTriangle () 
	{	
		boolean rev = false;
		
		//Find the largest side and check largest side ^2 =
		// side^2 + side^2
		
		if (side1 > side2 && side1 > side3)
		{
			//side1 is the biggest side
			if ( Math.pow(side1, 2) == (Math.pow(side2, 2) + Math.pow(side3, 2)))
					rev = true;
		}
		else if (side2 > side1 && side2 > side3)
		{
			if ( Math.pow(side2, 2) == (Math.pow(side1, 2) + Math.pow(side3, 2)))
				rev = true;			
		}
		else if (side3 > side1 && side3 > side2)
		{
			if ( Math.pow(side3, 2) == (Math.pow(side2, 2) + Math.pow(side1, 2)))
				rev = true;
		}
		
		return rev;
	}
	
	/*------------------------------------------------------
	 * getValidateInput: prompt user to enter the length
	 * of the sides of a triangle validate the input
	 * -----------------------------------------------------
	 */
	public boolean getValidatedInput () 
	{
		Scanner in = new Scanner(System.in);
		
	    System.out.println("Enter 3 sides of a triangle: ");
	    side1 = in.nextFloat();
	    side2 = in.nextFloat();
	    side3 = in.nextFloat();
	    
		// sides of a triangle must be greater than 0
		if ( (side1 <= 0.0) || (side2 <= 0.0) || ( side3 <= 0.0))
			return false;
		else			
			return true;
		
	}
	
	/*------------------------------------------------------
	 * TriangleType: Print the type of triangle based on the
	 * length of sides of the triangle
	 * -----------------------------------------------------
	 */
	public void printTriangleType ()
	{
		if ((side1==side2) && (side2==side3) && (side1==side3))
		{
			System.out.println("Equilateral Triangle");
		}
		else if ((side1==side2) || (side2==side3) || (side1==side3))
		{
			System.out.println("Isosceles Triangle");
		}
		else
			System.out.println("Scalene Triangle");
		
		if (isRightTriangle())
			System.out.println("is Right Triangle.\n");
		else
			System.out.println("is NOT Right Triangle.\n");
	}
	
	/*----------------------
	 * Main
	 * ---------------------
	 */
    public static void main(String[] args) {
    	Scanner in = new Scanner(System.in);
    	int totalTests = 0;
    	System.out.println("Enter total test no.");
    	totalTests = in.nextInt();
	    
    	decideTriangleType myTriangle = new decideTriangleType();
    	
    	while (totalTests > 0)
    	{
    	   if (myTriangle.getValidatedInput()) // must have valid input sides
    	      myTriangle.printTriangleType();  // figure out triangle type
    	   else
    		   System.out.println("Invalid input");
    	  
    	   totalTests--;
    	}
    } // Main
} // decideTriangleType
